﻿using System.Threading;
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml.Serialization;
using System.IO;
using System.Text.RegularExpressions;
using TravianHelper.hero;
using TravianHelper.app;
using TravianHelper.village;

namespace TravianHelper.tools
{
    public partial class FindOasisForm : Form
    {
        public FindOasisForm()
        {
            InitializeComponent();
        }

        private void getOasisMap()
        {
            int c = 0;
            for (int ii = -7; ii <= 7; ii++)
                for (int jj = -7; jj <= 7; jj++)
                {
                    int xx = ii * 30 - 15;
                    int yy = jj * 30 - 15;
                    String mapinfo = TravianApplicationContext.adapter.postRequestMapInfo(xx.ToString(), yy.ToString());
                    String pattern = "\"x\":\"(-?\\d+)\",\"y\":\"(-?\\d+)\",\"d\":\\-1,\"c\":\"{k.fo}\"";
                    Regex re = new Regex(pattern);
                    MatchCollection matches = re.Matches(mapinfo);
                    for (int i = 0; i < matches.Count; i++)
                    {
                        int x = Convert.ToInt32(matches[i].Groups[1].Value);
                        int y = Convert.ToInt32(matches[i].Groups[2].Value);
                        Zone zone = new Zone();
                        zone.x = x;
                        zone.y = y;
                        c++;
                        TravianApplicationContext.allOasis.Add(zone);
                        Console.WriteLine(ii + " " + jj + " " + c);
                    }

                }
            Util.SerializeArrayList(TravianApplicationContext.allOasis, "oasis.xml");
        }
    }
}
